#include <cstdlib>
#include <cstdio>
#include <ctime>
//using namespace std;

#define PROBLEM_NUMBER 10

char * good[] = { "Very good!", 
				  "Excellent!", 
				  "Nice work!",
				  "Keep up the good work!"};

char * bad[] = { "No. Please try again",
				 "Wrong. Try once more",
				 "Dont't give up!",
				 "No. Keep trying"};

int main(){
	srand( (unsigned)time( NULL ) );

	double percent = 0.0;
	double step = (double)PROBLEM_NUMBER / 100;

	while(1) {
		for (int i = 0; i < PROBLEM_NUMBER; ++i) {
			int a = rand()%9 + 1;
			int b = rand()%9 + 1;

			printf("How much is %d times %d? ", a, b);

			char c[10];
			fgets(c, 10, stdin);

			if (atoi(c) == a*b) {
				printf("%s\n\n", good[rand()%4]);
				percent += step;
			} else 
				printf("%s\n\n", bad[rand()%4]);
		}

		if (percent < 0.75) {
			percent = 0.0;
			printf("Please ask your instructor for extra help\n\n");
			continue;
		} else {
			percent = 0.0;
			printf("Nice work!\n");
			break;
		}
	}

	system("PAUSE");
	return 0;
}



